package com.fanbai.score.user.activity;

import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;

import com.fanbai.score.R;
import com.fanbai.score.common.Manager.ActivityManager;
import com.fanbai.score.common.Utils.ToastUtils;
import com.fanbai.score.common.base.BaseActivity;
import com.fanbai.score.common.http.CallBack;
import com.fanbai.score.user.http.UserRequestNetwork_Utils;

import butterknife.BindView;

/**
 * Created by acer on 2017/6/10.
 */

public class Feedback_Activity extends BaseActivity{

    @BindView(R.id.userActivityFeedback_content)
    EditText contentEdit;

    @Override
    protected int getLayoutID() {
        return R.layout.user_activity_feedback;
    }

    @Override
    public String getTitleName() {
        return "意见反馈";
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initListener() {

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_submit, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == R.menu.menu_submit) {
            if(contentEdit.getText().toString().trim().length() > 10){
                submitFeedBack(contentEdit.getText().toString().trim());
            }else{
                ToastUtils.WarnImageToast(ctx, "请输入至少十个字");
            }
        }
        return super.onOptionsItemSelected(item);
    }


    @Override
    public int getTitleLeftName() {
        return R.mipmap.back_click;
    }

    @Override
    public void onClickTitleLeft() {
        ActivityManager.getInstance().finishActivity();
    }


    private void submitFeedBack(String context){
        UserRequestNetwork_Utils.feedback(ctx, context, new CallBack<String>() {
            @Override
            public void onSuccess(String code, String msg, String s) {
                hideDialog();
                ToastUtils.RightImageToast(ctx, msg);
                ActivityManager.getInstance().finishActivity();
            }

            @Override
            public void onFailure(String code, String msg, String body) {
                hideDialog();
                ToastUtils.WarnImageToast(ctx, msg);
            }

            @Override
            public void onError(String code, String msg) {
                hideDialog();
                ToastUtils.ErrorImageToast(ctx, msg);
            }
        });
    }
}
